import axios from 'axios'
import Vue from "vue";
import router from "../router";
const http = axios.create({
  baseURL:'http://localhost:3000/admin/api'
})
http.interceptors.request.use(config=>{
  if(localStorage.getItem('token')){
    config.headers.Authorization = 'Bear ' + (localStorage.getItem('token') || '')
  }
  return config
})
http.interceptors.response.use(response=>{
   return response
},err =>{
  // console.log(err.response.data.message) //获取错误信息
  err.response.data.message && Vue.prototype.$message.error(err.response.data.message)
  err.response.status === 401?router.push('/login'):''
  return Promise.reject(err)
})
export default http
